#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from flask import Flask, render_template
from flask_sqlalchemy import SQLAlchemy
import pymysql
import os

app = Flask(__name__)  # 创建 app 对象
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql+pymysql://root:753951kzlAqie*aqie@127.0.0.1:3306/movie'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
app.config['SECRET_KEY'] = '287551f7b6ef46ed958b43afdd2f9feb'
# 定义电影文件上传保存路径
app.config['UP_DIR'] = os.path.join(os.path.abspath(os.path.dirname(__file__)), "static/uploads/")
# 定义用户头像上传路径
app.config['AVATAR_DIR'] = os.path.join(os.path.abspath(os.path.dirname(__file__)), "static/uploads/user/")
#app.debug = True
app.debug = False
db = SQLAlchemy(app)  # db 放在app实例化之后

# 从蓝图中导入对象
from app.home import home as home_blueprint
from app.admin import admin as admin_blueprint

app.register_blueprint(home_blueprint)
app.register_blueprint(admin_blueprint, url_prefix="/admin")  # 添加url前缀


@app.errorhandler(404)
def pag_not_found(error):
    return render_template("home/404.html"), 404
